#include "GoalList.h"

GoalList::GoalList()
{
	head = NULL;
}
GoalList::GoalList(Goal * headGoal)
{
	head = new List<Goal>(headGoal, NULL);
}
GoalList::~GoalList()
{
	printf("deleting goal list\n");
	List<Goal> * search = head;
	while(search)
	{
		search = search->Remove();
	}
	head = NULL;
	printf("done deleting goal\n");
}
List<Goal> * GoalList::Add(Goal * payload)
{
	head = new List<Goal>(payload, head);
	return head;
}
void GoalList::Remove(Goal * point)
{
	List<Goal> * search = head;
	while(search)
	{
		if(search->payload && search->payload ==  point)
		{
			search = search->Remove();
		}
		else
			search = search->next;
	}	
}
Goal * GoalList::GetCurrentGoal(CpuControlledVertibrateObject * character)
{
	//find the first goal in the chain that isn't yet complete
	List<Goal> * search = head;
	while(search)
	{
		if(search->payload)
		{
			if(!search->payload->IsGoalMet(character))
			{
				return search->payload;
			}
		}
		search = search->next;
	}
	return NULL;
}
